package com.oneandseven.dajia.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty("tencent.cos")
public class TencentCloudConfig {

    @Value("${tencent.cos.secret-id}")
    private String tencentCloudSecretId;

    @Value("${tencent.cos.secret-key}")
    private String tencentCloudSecretKey;


    @Bean
    public COSClient cosClient() {
        COSCredentials cred = new BasicCOSCredentials(tencentCloudSecretId, tencentCloudSecretKey);
        Region region = new Region("ap-shanghai");
        ClientConfig clientConfig = new ClientConfig(region);
        clientConfig.setHttpProtocol(HttpProtocol.https);
        return new COSClient(cred, clientConfig);
    }


}